﻿@using BXJG.Utils.Application.Share.GeneralTree
@using ZLJ.Application.Share.Post
@page "/data-dictionary"
@attribute [ReuseTabsPage(Title = "数据字典")]
@attribute [Authorize(BXJG.Utils.Application.Share.Auth.PermissionNames.GeneralTreeMenuName)]
@inherits TreeListBaseComponent<DataDictionaryDto, DataDictionaryGetTreeInput>
<Flex Gap="FlexGap.Small" Vertical Justify="FlexJustify.SpaceBetween">

    <Flex Gap="FlexGap.Small" Justify="FlexJustify.SpaceBetween">
         @* 左侧 *@
         <Flex Gap="FlexGap.Small">
             @if (createIsGranted)
            {
                <Button Type="@ButtonType.Primary" Icon="@IconType.Outline.Plus" OnClick="BtnCreateClick">新增</Button>
            }
            @if (deleteIsGranted)
            {
                <Popconfirm Title="将删除已经的项及其所有子项，确定删除吗?"
                            OnConfirm="BtnDeleteClick">
                    <Button Type="@ButtonType.Default" Icon="@IconType.Outline.Clear" Danger="true" Loading=isDeleting Disabled="@ShouldDisableDelete">删除</Button>
                </Popconfirm>
            }
        </Flex>
        @* 右侧 *@
        <Flex Gap="FlexGap.Small">
            <RadioGroup TValue="bool?" @bind-Value="@GetAllInput.IsSysDefine" OnChange="BtnSearchClick" Disabled=IsLoading>
                <Radio TValue="bool?" RadioButton="true" Value="@(default(bool?))">全部</Radio>
                <Radio TValue="bool?" RadioButton="true" Value="@(true)">预设</Radio>
                <Radio TValue="bool?" RadioButton="true" Value="@(false)">非预设</Radio>
            </RadioGroup>
            @*Search组件有问题，设置宽度会错位 *@
            <div style="width:15rem;">
                <Search Placeholder="请输入关键字..." @bind-Value="@Keywords" OnChange=BtnSearchClick AllowClear="true" ClassicSearchIcon="true" Disabled=IsLoading />
            </div>
            <Tooltip Title="清空条件">
                <Button Type="@ButtonType.Default" Icon="@IconType.Outline.Clear" OnClick="BtnClearFilterClick" Disabled=IsLoading></Button>
            </Tooltip>
            <Tooltip Title="刷新">
                <Button Type="@ButtonType.Default" Icon="@IconType.Outline.Reload" OnClick="BtnRefreshClick" Disabled=IsLoading></Button>
            </Tooltip>
        </Flex>
    </Flex>

    @* 不能定义key，不然无法刷新子节点 *@
    <Table @ref="table"
           TreeChildren=GetTreeChildren
           TItem="DataDictionaryDto"
           Total="TotalCount"
           @bind-SelectedRows="SelectedItems"
           OnChange="OnQuery"
           DataSource="Items"
           Loading="IsLoading"
           HidePagination=true
           RowClassName="@(r=>r.RowIndex%2==0?"even":"odd")"
           RemoteDataSource="true"
           OnRow="Row"
           Size="TableSize.Small"
           Bordered="true"
           ScrollY="76vh">
        <Selection Key="@(context.Id.ToString())" />
        <PropertyColumn Property="c=>c.DisplayName" Sortable="true" DefaultSortOrder="SortDirection.Ascending" ShowSorterTooltip="false" />
        <PropertyColumn Property="c=>c.IsSysDefine" Width="80">
            <Switch @bind-Value="@context.IsSysDefine" Size="@InputSize.Small" Disabled="true"></Switch>
        </PropertyColumn>
        <ActionColumn Title="操作" Width="240">
            <ButtonGroup Size="@ButtonGroupSize.Small">
                <Button Size="@ButtonSize.Small" Type="@ButtonType.Primary" OnClick="x=>BtnItemDetailClick(context)">详情</Button>
                @if (createIsGranted)
                {
                    <Button Size="@ButtonSize.Small" OnClick="x=>BtnAddSubClick(context.Id)">添加子节点</Button>
                }
                @if (updateIsGranted)
                {
                    <Button Size="@ButtonSize.Small" OnClick="x=>BtnItemEditClick(context)">修改</Button>
                }
                @if (deleteIsGranted)
                {
                    <Popconfirm Title="将删除此项及其所有子项，确定删除吗?"
                                OnConfirm="()=>BtnDeleteItemClick(context)">
                        <Button Size="@ButtonSize.Small" Danger="true" Loading=@context.ExtensionData.IsDeleting>删除</Button>
                    </Popconfirm>
                }
            </ButtonGroup>
        </ActionColumn>
    </Table>

</Flex>

@{
    RenderFragment renderFragment =@<Template>
        <SectionOutlet SectionName=@($"{GetHashCode()}-create-btns") />
        <Button OnClick="BtnCloseCreateClick">关闭</Button>
    </Template>;
}
<Modal DestroyOnClose="true" Footer="renderFragment" @bind-Visible="isShowCreateDialog" Draggable="true" Width=@("40vw") AfterClose="AfterCloseDialog"
       Class="frm-dal">
    <TitleTemplate>
        <Icon Type="plus" Theme="IconThemeType.Outline" />
        新增@(FuncName)
    </TitleTemplate>

    <ChildContent>
        <SectionOutlet SectionName="@($"{GetHashCode()}-create-body" )" />
        <Create OnAddEnd="AddEnd" ParentId="parentId" Master="GetHashCode()" />
    </ChildContent>
</Modal>

@{
    RenderFragment renderFragment1 =@<Template>
        <SectionOutlet SectionName=@($"{GetHashCode()}-detail-update-btns") />
        <Button OnClick="BtnDetailUpdateCloseClick">关闭</Button>
    </Template>;
}
<Modal DestroyOnClose="true" Footer="renderFragment1" @bind-Visible="isShowDetailUpdateDialog" Draggable="true" Width=@("40vw") AfterClose="AfterCloseDialog"
       Class="frm-dal">
    <TitleTemplate>
        <SectionOutlet SectionName=@($"{GetHashCode()}-detail-update-title") />
    </TitleTemplate>
    <ChildContent>
        <SectionOutlet SectionName=@($"{GetHashCode()}-detail-update-body") />
        <DetailUpdate Id=detailUpdateId IsEdit=isEdit OnDeleted=DetailDeleted OnUpdated=DetailUpdated  Master="GetHashCode()" />
    </ChildContent>
</Modal>